//
//  SideBarViewController.m
//  GolfFriend
//
//  Created by Vescky on 13-11-26.
//  Copyright (c) 2013年 vescky.org. All rights reserved.
//

#import "SideBarViewController.h"
#import "AppDelegate.h"
#import <QuartzCore/QuartzCore.h>
#import "UserSession.h"
#import "UIImageView+MJWebCache.h"
#import "PersonalInfoViewController.h"

@interface SideBarViewController ()

@end

@implementation SideBarViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
//    [self.view setBackgroundColor:GetColorWithRGB(72, 182, 159)];
    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self initView];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)initView {
    imgAvatar1.layer.cornerRadius = imgAvatar1.frame.size.width / 2;
    imgAvatar2.layer.cornerRadius = imgAvatar2.frame.size.width / 2;
    NSString *avatarLink = [[[UserSession shareUserSession] getUserPublicInfo] objectForKey:@"avatar"];
    if ([avatarLink stringByMatching:Qiniu_Domain]) {
        avatarLink = GetQiniuResizeImageLink(avatarLink, 160);
    }
    NSString *userName = [[UserSession shareUserSession] getUserName];
    NSString *score = [NSString stringWithFormat:@"%@",[[[UserSession shareUserSession] getUserPublicInfo] objectForKey:@"prestige"]];
    if (!iPhone5) {
        [viewHead1 removeFromSuperview];
        [self.view addSubview:viewHead2];
        CGRect vheadRect = viewHead2.frame;
        CGRect v2Rect = view2.frame;
        CGRect v3Rect = view3.frame;
        vheadRect.origin.y = 20;
        v2Rect.origin.y = vheadRect.origin.y + vheadRect.size.height + 5.0;
        v3Rect.origin.y = v2Rect.origin.y + v2Rect.size.height + 5.0;
        viewHead2.frame = vheadRect;
        view2.frame= v2Rect;
        view3.frame = v3Rect;
        
        labelUserName2.text = userName;
        labelScore2.text = score;
        [imgAvatar2 setImageURLStr:avatarLink placeholder:Default_Avatar];
    }
    else {
        labelUserName1.text = userName;
        labelScore1.text = score;
        [imgAvatar1 setImageURLStr:avatarLink placeholder:Default_Avatar];
    }
}

#pragma mark - Public
- (IBAction)btnAction:(id)sender {
    UIButton *btn = (UIButton*)sender;
    NSString *classString,*webappLink,*vTitle;
    if (btn.tag == 101) {
        //高端品鉴
        classString = @"NewsListViewController";
    }
    else if (btn.tag == 102) {
        //活动资讯
        classString = @"NewsListViewController";
    }
    else if (btn.tag == 103) {
        //关于名媛
        classString = @"WebappBrowserViewController";
        webappLink = @"http://wap.koudaitong.com/v2/showcase/feature?alias=dau5r9ar";
        vTitle = @"关于名媛";
    }
    else if (btn.tag == 104) {
        //名媛展示
//        classString = @"WebappBrowserViewController";
//        webappLink = @"http://golffriend.sinaapp.com/test/webveiw/yueqiu.html";
//        vTitle = @"约TA打球";
        classString = @"WebappBrowserViewController";
        webappLink = @"http://mingyuanhui.sinaapp.com/test/webveiw/jiaolian.html";
        vTitle = @"名媛展示";
    }
    else if (btn.tag == 105) {
        //附近名媛
        classString = @"NearbyFriendsViewController";
    }
    else if (btn.tag == 106) {
        //名媛展示
//        classString = @"WebappBrowserViewController";
//        webappLink = @"http://mingyuanhui.sinaapp.com/test/webveiw/jiaolian.html";
//        vTitle = @"名媛展示";
    }
    else if (btn.tag == 107) {
        //会员产品
//        classString = @"ContactBookViewController";
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://shop509990.koudaitong.com/v2/showcase/homepage?kdt_id=317822&spm=f1620017&from=singlemessage&amp;isappinstalled=0"]];
        return;
    }
    else if (btn.tag == 108) {
        //商家推荐
        classString = @"NearbyStadiumList";
    }
    else if (btn.tag == 109) {
        //粉红工程
        classString = @"WebappBrowserViewController";
        webappLink = @"http://mp.weixin.qq.com/s?__biz=MzA4OTgxNTAyMQ==&mid=200815630&idx=1&sn=3726192526d727b11896066a5312080e&;scene=2&;from=singlemessage&isappinstalled=0#rd";
        vTitle = @"粉红工程";
    }
    else if (btn.tag == 110) {
        //设置
        classString = @"SettingViewController";
    }
    else if (btn.tag == 111) {
        //个人信息
        PersonalInfoViewController *pVc = [[PersonalInfoViewController alloc] init];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:[[UserSession shareUserSession] getUserPublicInfo]];
        if ([dict objectForKey:@"uId"]) {
            [dict setObject:[dict objectForKey:@"uId"] forKey:@"userId"];
        }
        pVc.userInfo = dict;
        [self.navigationController pushViewController:pVc animated:YES];
        return;
    }
    
    id obj = NSClassFromString(classString);
    UIViewController *vc = [[obj alloc] init];
    
    if ([vc respondsToSelector:@selector(setWebappLink:)]) {
        [vc performSelector:@selector(setWebappLink:) withObject:webappLink];
        [vc setTitle:vTitle];
    }
    if (btn.tag == 101) {
        //高端品鉴
        if ([vc respondsToSelector:@selector(setNewsListType:)]) {
            [vc performSelector:@selector(setNewsListType:) withObject:@1];
        }
    }
    
    [[APP_DELEGATE navigationController] pushViewController:vc animated:YES];
    
}

@end
